/**
 * Carnegie Mellon University
 * School of Computer Science
 * MSIT eBusiness Technology
 * 
 * Team 8 - Infinity (2011 Spring)
 * infinity-team8@googlegroups.com
 * 
 * Professor: Jeffrey L. Eppinger
 * Program Faculty: Sujata Telang
 */

package controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.mybeans.dao.DAOException;

import model.Model;
import model.CustomerDAO;


/*
 * Logs out by setting the "user" session attribute to null.
 * (Actions don't be much simpler than this.)
 */
public class CustomerLogoutAction extends Action {

	private CustomerDAO  customerDAO;
	public CustomerLogoutAction(Model model) {
		customerDAO  = model.getCustomerDAO();
	}
	
	public String getName() { return "customer-logout.do"; }

	public String perform(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session = request.getSession(false);
        session.setAttribute("customer",null);
        
        
        List<String> errors = new ArrayList<String>();
        // Set up user list for nav bar
		try {
			request.setAttribute("customerList",customerDAO.getCustomers());
		} catch (DAOException e) {
			errors.add(e.getMessage());
        	return "customer-error.jsp";
		}
        

		request.setAttribute("message","You are now logged out");
        return "customer-login.do";
    }
}
